<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue-2.4.0.js"></script>
    <script src="./lib/vue-router-3.0.1.js"></script>
</head>
<body>
        <div id="app">
            <router-link to="/login">登录</router-link>
            <router-link to="/register">注册</router-link>
            <router-view></router-view>
        </div>
        <script>
            //创建子组件
            var login = {
                template:'<h1>我是登录</h1>'
            }
            var register = {
                template:'<h1>我是注册</h1>'
            }
            let router = new VueRouter({
                routes: [
                    {path:'/',redirect:'/login'},
                    {path:'/login',component:login},
                    {path:'/register',component:register}
                ]
            })
            new Vue({
                el:"#app",
                data:{},
                methods: {
                    
                },
                router,
                // created(){
                //     console.log('====================================');
                //     console.log(this.$route);
                //     console.log('====================================');  
                //     },
                watch:{       
                    $route(to,from){
                        if(to.path === '/login'){
                            console.log("欢迎来到登录页面");
                            
                        }else if(to.path === '/register'){
                            console.log('====================================');
                            console.log("欢迎来注册页面");
                            console.log('====================================');
                        }
                    }
                }
            })
        </script>
</body>
</html>